// This kernel perform vectorized floating-point addition/multiplication
// to demonstrate how parallel processing can accelerate computation
// 2020.06.17 by wangdong@bjtu.edu.cn
//#include "ap_int.cnt_h"
//#include <stdio.cnt_h> 


//没什么修改

#include "custypedef.h"

//--------------------- Baseline -----------------------//

// void funcUp

extern "C" {
void memWrite(
			DATA_TYPE *C_out,
			REFERENCE_STREAM(k2k<result_bag>, 256, result_channels)
){
	#pragma HLS INTERFACE m_axi port = C_out       offset = slave bundle = gmem2
	#pragma HLS INTERFACE axis  port = result_channels depth=256
	DATA_TYPE r;
	volatile int Wrcnt = 0;
	int acc_tmp[FADD_LAT];
	for(uint cnt_m = 0; cnt_m < DATA_SIZE_M/KERNAL_PARALLEL; cnt_m++){
	
		for(int cnt_h = 0; cnt_h < DATA_SIZE_H - DATA_SIZE_K + 1; cnt_h++){
			
			for(int cnt_i = 0; cnt_i< DATA_SIZE_W - DATA_SIZE_K + 1; cnt_i++){

				k2k<result_bag> _trans_r;
				_trans_r = result_channels.read();		

				for(uint kp = 0; kp<KERNAL_PARALLEL; kp++){	
					r = _trans_r.data(kp*GET_BIT(DATA_TYPE)+GET_BIT(DATA_TYPE)-1, kp*GET_BIT(DATA_TYPE));
					C_out[(cnt_m*KERNAL_PARALLEL+kp) * (DATA_SIZE_W - DATA_SIZE_K + 1) * (DATA_SIZE_H - DATA_SIZE_K + 1) + cnt_h * (DATA_SIZE_W - DATA_SIZE_K + 1) + cnt_i] = r;
					++Wrcnt;					
				}

			}
		}
	}
}
}

